package model.forview;

import java.util.Iterator;
import java.util.Map;

import models.ConstantName;
import models.ConstantValue;

public class RegistrationModelForView extends ContentForMainTemplate
{
	public String		emailLabel;
	public String		passwordLabel;
	public String		rewritePasswordLabel;
	public String		firstNameLabel;
	public String		lastNameLabel;
	public String		saveButton;
	public String		cancelButton;
	public String		email;
	public String		password;
	public String		rewritePassword;
	public String		firstName;
	public String		lastName;

	public final String	emailName			= "email";
	public final String	passwordName		= "password";
	public final String	rewritePasswordName	= "rewritePassword";
	public final String	firstNameName		= "firstName";
	public final String	lastNameName		= "lastName";

	// public MainModelForView mainModelForView;

	public RegistrationModelForView(Map<String, String> form)
	{
		Iterator<String> keys = form.keySet().iterator();
		while (keys.hasNext())
		{
			String key = keys.next();
			if (key.equals("data["+this.emailName+"]"))
				this.email = form.get(key);
			if (key.equals("data["+this.passwordName+"]"))
				this.password = form.get(key);
			if (key.equals("data["+this.firstNameName+"]"))
				this.firstName = form.get(key);
			if (key.equals("data["+this.lastNameName+"]"))
				this.lastName = form.get(key);
		}
	}

	public RegistrationModelForView()
	{
		setDefaultValue();
	}

	public void setDefaultValue()
	{
		emailLabel = ConstantValue.getConstantValue(ConstantName.EMAIL);
		passwordLabel = ConstantValue.getConstantValue(ConstantName.PASSWORD);
		rewritePasswordLabel = ConstantValue.getConstantValue(ConstantName.REWRITE_PASSWORD);
		firstNameLabel = ConstantValue.getConstantValue(ConstantName.FIRST_NAME);
		lastNameLabel = ConstantValue.getConstantValue(ConstantName.LAST_NAME);
		saveButton = ConstantValue.getConstantValue(ConstantName.SAVE_BUTTON);
		cancelButton = ConstantValue.getConstantValue(ConstantName.CANCEL_BUTTON);

		emailLabel = emailLabel != null ? emailLabel : "email";
		passwordLabel = passwordLabel != null ? passwordLabel : "password";
		rewritePasswordLabel = rewritePasswordLabel != null ? rewritePasswordLabel : "rewritePassword";
		firstNameLabel = firstNameLabel != null ? firstNameLabel : "firstName";
		lastNameLabel = lastNameLabel != null ? lastNameLabel : "lastName ";
		saveButton = saveButton != null ? saveButton : "saveButton";
		cancelButton = cancelButton != null ? cancelButton : "cancelButton";

		String title = ConstantValue.getConstantValue(ConstantName.REGISTRATION_PAGE_TITLE);
		title = title != null ? title : "Регистрация";
		String userName = "";
		String header = ConstantValue.getConstantValue(ConstantName.REGISTRATION_PAGE_HEADER);
		header = header != null ? header : "Регистрация в системе";
		String footer = ConstantValue.getConstantValue(ConstantName.REGISTRATION_PAGE_FOOTER);
		footer = footer != null ? footer : "Регистрация";
		mainModelForView = new MainModelForView(title, userName, header, footer);
	}
}
